const path = require('path');
const CracoLessPlugin = require('craco-less');

module.exports = {
  webpack: {
    alias: {
      '@': path.resolve(__dirname, 'src'),
    },
    configure: {
      ignoreWarnings: [
        {
          module: /node_modules\/@antv\/util/,
        },
        {
          module: /node_modules\/@antv\/component/,
        },
      ],
    },
  },
  plugins: [
    {
      plugin: CracoLessPlugin,
      options: {
        lessLoaderOptions: {
          lessOptions: {
            javascriptEnabled: true,
          },
        },
        modifyLessRule: function (lessRule, _context) {
          lessRule.test = /\.(module)\.(less)$/;
          lessRule.exclude = /node_modules/;
          return lessRule;
        },
      },
    },
  ],
  // 添加开发服务器代理配置
  devServer: {
    proxy: {
      '/api/v1': {
        // target: 'http://119.254.155.240:5896',
        target: 'http://10.1.60.39:5896',
        changeOrigin: true,
        pathRewrite: {},
        onProxyReq: (proxyReq, req) => {
          // 用于调试请求
          console.log('代理请求URL:', `${proxyReq.protocol}//${proxyReq.host}${proxyReq.path}`);
          console.log('原始请求URL:', req.url);
        },
        onError: (err) => {
          // 代理错误处理
          console.error('代理错误:', err);
        },
      },
    },
  },
};
